#include <sstream>
#include "InsteadHttpUrl.h"

using namespace std;

void InsteadHttpUrl::ParseUrl(const string &url)
{
	string::size_type index=url.find(":",5);
	string::size_type indexPath=url.find("/",7);
	if(index!=string::npos&&indexPath!=string::npos&&index<indexPath)
	{
		m_serverName=url.substr(7,index-7);
		m_serverPort=static_cast<unsigned short>(atoi(url.substr(index+1,indexPath-index).c_str()));
	}
	else if(index!=string::npos&&indexPath==string::npos)
	{
		m_serverName=url.substr(7,index-7);
		m_serverPort=static_cast<unsigned short>(atoi(url.substr(index+1).c_str()));
	}
	else
	{
		m_serverName=url.substr(7,indexPath-7);
		m_serverPort=80;
	}
	if(indexPath!=string::npos)
	{
		m_path=url.substr(indexPath);
	}
}